package algorithmExample;

import java.util.Arrays;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/2 10:14
 */
//题目:https://leetcode-cn.com/problems/first-missing-positive/
public class FirstMissingPositive {
    public int firstMissingPositive(int[] nums) {
        quickSort(nums, 0, nums.length - 1);
        return 0;
    }

    private void quickSort(int[] nums, int start, int end) {
        if (start < end) {
            int pos = getIndexVal(nums, start, end);

            quickSort(nums, start, pos - 1);
            quickSort(nums, pos + 1, end);
        }

    }

    private int getIndexVal(int[] nums, int start, int end) {
        int indexVal = nums[start];
        while (start < end) {
            while (start < end && nums[end] >= indexVal) {
                end--;
            }
            nums[start] = nums[end];

            while (start < end && nums[start] <= indexVal) {
                start++;
            }
            nums[end] = nums[start];
        }
        nums[start] = indexVal;
        return start;
    }

    public static void main(String[] args) {
        int[] input = new int[]{2, 1, 3, 5, 62, 1, 8};
        new FirstMissingPositive().quickSort(input, 0, input.length - 1);
        System.out.println(Arrays.toString(input));
    }
}
